# -*-coding = utf-8 -*-

# @Time: 2021/5/1 1:09
# @Author: bistro
# @File: p690.py
# @Software: PyCharm
# 690. 员工的重要性
from typing import List


class Employee:
    def __init__(self, id: int, importance: int, subordinates: List[int]):
        self.id = id
        self.importance = importance
        self.subordinates = subordinates


class Solution:

    def getImportance(self, employees: List['Employee'], id: int) -> int:
        hashmap = {emp.id: emp for emp in employees}
        # print(hashmap)
        return self.traverse(id, hashmap)

    def traverse(self, eid, hashmap):
        emp = hashmap[eid]
        total = emp.importance
        for e in emp.subordinates:
            total += self.traverse(e, hashmap)
        return total
